package com.hzncc.flowable_diboot.project_contracts.vo;

import com.diboot.core.binding.annotation.BindEntity;
import com.diboot.core.binding.annotation.BindEntityList;
import com.diboot.core.binding.annotation.BindField;
import com.diboot.iam.entity.IamUser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hzncc.flowable_diboot.entity.SapCustomer;
import com.hzncc.flowable_diboot.enums.ItemtypeEnum;
import com.hzncc.flowable_diboot.project_contracts.entity.*;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 项目类合同评审 VO定义
 *
 * @author MyName
 * @version 1.0
 * @date 2024-09-24
 * Copyright © MyCorp
 */
@Getter
@Setter
@Accessors(chain = true)
public class ProjectContractAuditDetailVO extends ProjectContractAuditListVO {
    private static final long serialVersionUID = 1205205695894200120L;

    /**
     * 合同金额
     */
    @BindEntity(
            entity = ProjectContractAmount.class,
            condition = "this.id = contract_id",
            deepBind = true
    )
    private ProjectContractAmountDetailVO projectContractAmount;

    /**
     * 项目合同
     */
    @BindEntityList(
            entity = ProjectContractItem.class,
            condition = "this.id = contract_id and itemType = 1",
            deepBind = true
    )
    private List<ProjectContractItemDetailVO> contractItemList;

    /**
     * 销售费用
     */
    @BindEntityList(
            entity = ProjectContractItem.class,
            condition = "this.id = contract_id and itemType = 2",
            deepBind = true
    )
    private List<ProjectContractItemDetailVO> salesItemList;

    /**
     * 自制
     */
    @BindEntityList(
            entity = ProjectContractItem.class,
            condition = "this.id = contract_id and itemType = 4",
            deepBind = true
    )
    private List<ProjectContractItemDetailVO> homemadeItemList;

    /**
     * 无成本
     */
    @BindEntityList(
            entity = ProjectContractItem.class,
            condition = "this.id = contract_id and itemType = 3",
            deepBind = true
    )
    private List<ProjectContractItemDetailVO> noCostItemList;

    /**
     * 产品供销合同
     */
    @BindEntity(
            entity = ProjectSamContract.class,
            condition = "this.id = contract_id",
            deepBind = true
    )
    private ProjectSamContractDetailVO projectSamContract;

    /**
     * 合同变更
     */
    @BindEntity(
            entity = ProjectContractUpdate.class,
            condition = "this.id = contract_id",
            deepBind = true
    )
    private ProjectContractUpdateDetailVO projectContractUpdate;

    /**
     * 合同取消
     */
    @BindEntity(
            entity = ProjectContractCancel.class,
            condition = "this.id = contract_id",
            deepBind = true
    )
    private ProjectContractCancelDetailVO projectContractCancel;

    @BindEntityList(
            entity = ProjectPaymentCollectionPlan.class,
            condition = "this.id = contract_id",
            deepBind = true
    )
    private List<ProjectPaymentCollectionPlanDetailVO> planList;

    /**
     * 合同项目变更比较
     */
    private List<ProjectDiffVO> diffVOS;

    @BindField(
            entity = SapCustomer.class,
            field = "sapNo",
            condition = "this.customerId = id"
    )
    private String customerSapNo;

    @BindField(
            entity = IamUser.class,
            field = "userNum",
            condition = "this.saler = id"
    )
    private String salerNum;

    /**
     * 扩展属性
     */
    private Map<String, Object> extendedProperties;


    public List<ProjectContractItemDetailVO> collectItemList() {
        List<ProjectContractItemDetailVO> contractItemList = this.getContractItemList();
        List<ProjectContractItemDetailVO> salesItemList = this.getSalesItemList();
        List<ProjectContractItemDetailVO> homemadeItemList = this.getHomemadeItemList();
        List<ProjectContractItemDetailVO> noCostItemList = this.getNoCostItemList();
        List<ProjectContractItemDetailVO> itemDetailVOS = new ArrayList<>();
        if (contractItemList != null && contractItemList.size() > 0) {
            itemDetailVOS.addAll(contractItemList);
        }
        if (salesItemList != null && salesItemList.size() > 0) {
            for (int i = 0; i < salesItemList.size(); i++) {
                ProjectContractItemDetailVO item = salesItemList.get(i);
                item.setItemType(ItemtypeEnum.sales.getCode());
                item.setSerialNumber((i + 1) * 10L);
            }
            itemDetailVOS.addAll(salesItemList);
        }
        if (homemadeItemList != null && homemadeItemList.size() > 0) {
            for (int i = 0; i < homemadeItemList.size(); i++) {
                ProjectContractItemDetailVO item = homemadeItemList.get(i);
                item.setItemType(ItemtypeEnum.homemade.getCode());
                item.setSerialNumber((i + 1) * 10L);
            }
            itemDetailVOS.addAll(homemadeItemList);
        }
        if (noCostItemList != null && noCostItemList.size() > 0) {
            for (int i = 0; i < noCostItemList.size(); i++) {
                ProjectContractItemDetailVO item = noCostItemList.get(i);
                item.setItemType(ItemtypeEnum.noCost.getCode());
                item.setSerialNumber((i + 1) * 10L);
            }
            itemDetailVOS.addAll(noCostItemList);
        }
        return itemDetailVOS;
    }

    public List<ProjectContractItem> addList;

    private List<ProjectContractItem> delList;

    private List<Map<String, Object>> amountList;

}